package com.tuananh.radnom.persist.imp.xml;

import java.util.ArrayList;

import com.ajexperience.utils.DeepCopyException;
import com.ajexperience.utils.DeepCopyUtil;
import com.tuananh.radnom.model.NetElementConfiguration;
import com.tuananh.radnom.model.thresholding.AbstractThresholder;
import com.tuananh.radnom.model.thresholding.ThresholderConfiguration;
import com.tuananh.radnom.persist.IThresholderDAO;

public class ThresholderXmlDAO extends XmlDAO implements IThresholderDAO {
	ThresholderConfiguration thresholderConfig;
	
	public ThresholderXmlDAO(){
		super(ThresholderConfiguration.path);
		System.out.println("Thresholder constructor");
		configuration = XmlConfigHolder.thresholderConfig;
		try {
			savedConfiguration = (new DeepCopyUtil()).deepCopy(configuration);
		} catch (DeepCopyException e) {
			// TODO Auto-generated catch block
			savedConfiguration = new NetElementConfiguration();
			e.printStackTrace();
		}
		thresholderConfig = (ThresholderConfiguration) configuration;
	}
	public ArrayList<AbstractThresholder> getAll() {
		// TODO Auto-generated method stub
		return thresholderConfig.getThresholder();
	}

	public AbstractThresholder getByName(String name) {
		// TODO Auto-generated method stub
		ArrayList<AbstractThresholder> list = getAll();
		for(AbstractThresholder thresholder:list){
			if (thresholder.getName().equals(name)){
				return thresholder;
			}
		}
		return null;
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return "ThresholderEvent";
	}

}
